package org.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import org.dk.domain.DataResult;
import org.dk.em.DataResultEnum;
import org.dk.pojo.SpecVo;
import org.dk.pojo.TbItemCat;
import org.dk.pojo.TbTypeTemplate;
import org.dk.service.TbItemCatService;
import org.dk.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("typeTemplate")
@Controller
public class TypeTemplateController {

    @Reference
    private TbTypeTemplateService typeTemService;

    @Reference
    private TbItemCatService itemCatService;

    @RequestMapping("selectTemplate")
    @ResponseBody
    public DataResult selectTemplate(Long id){
        try {
            TbItemCat itemCat = itemCatService.selectById(id);
            TbTypeTemplate tbTypeTemplate = typeTemService.selectById(itemCat.getTypeId());
            Map<String,Object> map = new HashMap<>();
            map.put("itemCat",itemCat);
            map.put("tbTypeTemplate",tbTypeTemplate);
            return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(map);
        }catch (Exception e){
            e.printStackTrace();
            return DataResult.buildDataResult(DataResultEnum.ERROR);
        }
    }

    @RequestMapping("selectSpec")
    @ResponseBody
    public DataResult selectTempoption(Long id){
        List<SpecVo> specVoList = typeTemService.selectTemplateoption(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(specVoList);
    }
}
